home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / bm_src.arc / pc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-28  |  4.6 KB  |  216 lines

  1. /* This file contains machine specific functions */
  2. #include <stdio.h>
  3.  
  4. /* This file is an attempt at keeping thing portble while taking
  5. * advantage of some of the faster io functions in the turbo lib.
  6. * It seems they all do it their own way but here it goes
  7. */
  8.  
  9. /* directory search utility for DOS */
  10. #if    defined(MICROSOFT)
  11. #include <sys/types.h>
  12. #endif
  13. #if    defined(MICROSOFT) || defined(AZTEC)
  14. #include <signal.h>
  15. #endif
  16. #if    defined(MICROSOFT) || defined(__TURBOC__)
  17. #include <sys/stat.h>
  18. #include <dos.h>
  19. #include <conio.h>
  20. #define ST_RDONLY    0x01    /* read only file */
  21. #define ST_HIDDEN    0x02    /* hidden file */
  22. #define ST_SYSTEM    0x04    /* system file */
  23. #define ST_VLABEL    0x08    /* volume label */
  24. #define ST_DIRECT    0x10    /* file is a sub-directory */
  25. #define ST_ARCHIV    0x20    /* set when file has been written and closed */
  26. #endif
  27. #ifdef AZTEC
  28. #include <stat.h>
  29. #endif
  30.  
  31. #define REGFILE    (ST_HIDDEN|ST_SYSTEM|ST_DIRECT)
  32. #define    SET_DTA        0x1a
  33. #define    FIND_FIRST    0x4e
  34. #define    FIND_NEXT    0x4f
  35.  
  36. struct dirent {
  37.     char rsvd[21];
  38.     char attr;
  39.     short ftime;
  40.     short fdate;
  41.     long fsize;
  42.     char fname[13];
  43. };
  44. /* wildcard filename lookup */
  45. filedir(name,times,ret_str)
  46. char *name;
  47. int times;
  48. char *ret_str;
  49. {
  50.     register char *cp,*cp1;
  51.     static struct dirent sbuf;
  52. #if    defined(MICROSOFT) || defined(__TURBOC__)
  53.     union REGS regs;
  54. #endif
  55.  
  56.     bdos(SET_DTA,(unsigned)&sbuf,0);    /* Set disk transfer address */
  57.  
  58. #if    defined(MICROSOFT) || defined(__TURBOC__)
  59.     regs.h.ah = (times == 0) ? FIND_FIRST : FIND_NEXT;
  60.     regs.x.dx = (unsigned int) name;
  61.     regs.x.cx = (unsigned int) REGFILE;
  62.     intdos(®s,®s);
  63.     if (regs.x.cflag) 
  64.         sbuf.fname[0] = '\0';
  65. #else
  66.     /* Find matching file */
  67.     if(dos(times == 0 ? FIND_FIRST:FIND_NEXT,0,REGFILE,name,0,0) == -1)
  68.         sbuf.fname[0] = '\0';
  69. #endif
  70.  
  71.     /* Copy result to output, forcing to lower case */
  72.     for(cp = ret_str,cp1 = sbuf.fname; cp1 < &sbuf.fname[13] && *cp1 != '\0';)
  73.         *cp++ = tolower(*cp1++);
  74.     *cp = '\0';
  75. }
  76.  
  77. /* This function should put the tty in a mode such that signgle characters
  78. * can be read without waiting for a complete line. Echo should be on.
  79. */
  80. setrawmode()
  81. {}
  82.  
  83. /* This function should restore the tty modes back to cooked mode */
  84. setcookedmode()
  85. {}
  86.  
  87. /* This function return one charater form the keyboard. It will wait
  88. * for a character to be input. This function will echo the character.
  89. * This funtion will return afer each character is typed if rawmode is set
  90. */
  91. int
  92. getrch()
  93. {
  94.     int    c;
  95. #if    defined(AZTEC) || defined(MICROSOFT) || defined(__TURBOC__)
  96.     c = bdos(1,0,0);
  97. #endif
  98.     return(c & 0xff);
  99. }
  100.  
  101. /* This function show clear screen and put cursor at top of screen */
  102. screen_clear()
  103. {
  104. #ifdef AZTEC
  105.     extern    int    scr_clear();
  106.     scr_clear();    /* from lib S */
  107. #endif
  108. #if    defined(MICROSOFT) || defined(__TURBOC__)
  109. #if defined(PLUS)
  110.     printf("\033[2J"); /* ANSI is available on the PLUS */
  111. #else
  112.     /* clear screen using window scroll up */
  113.     union REGS regs;
  114.     regs.h.ah = 6;
  115.     regs.h.al = 0;
  116.     regs.h.ch = 0;
  117.     regs.h.cl = 0;
  118.     regs.h.dh = 24;
  119.     regs.h.dl = 79;
  120.     regs.h.bh = 7;
  121.     int86(0x10,®s,®s);
  122.     /* home the cursor */
  123.     regs.h.ah = 2;
  124.     regs.h.bh = 0;
  125.     regs.h.dh = 0;
  126.     regs.h.dl = 0;
  127.     int86(0x10,®s,®s);
  128. #endif
  129. #endif
  130. }
  131.  
  132. #ifdef AZTEC
  133. /* This is the aztec specific setvbuf since the Aztec lib doesnt have one */
  134. setvbuf(stream,buffer,type,size)
  135. register FILE *stream;
  136. char *buffer;
  137. int type;
  138. int size;
  139. {
  140.     if (stream->_buff)
  141.         return;
  142.     if (buffer && type != _IONBF) {
  143.         stream->_buff = buffer;
  144.         stream->_buflen = size;
  145.     } else {
  146.         stream->_buff = &stream->_bytbuf;
  147.         stream->_buflen = 1;
  148.     }
  149. }
  150. #endif
  151.  
  152.  
  153.  
  154.  
  155. #if    defined(MICROSOFT) || defined(AZTEC)
  156. setsignals()
  157. {
  158.     signal(SIGINT,SIG_IGN);
  159. }
  160. #endif
  161.  
  162. #if    defined(__TURBOC__)
  163. /* dummy do nothing */
  164. int catchit() {}
  165.  
  166. setsignals()
  167. {
  168.     ctrlbrk(catchit);
  169. }
  170.  
  171.  
  172. setvideo(s)
  173. char *s;
  174. {
  175. #if defined(PLUS)
  176.     directvideo = 0;
  177. #else
  178.     if (strncmp("bios",s,4) == 0)
  179.         directvideo = 0;
  180.     else
  181.         directvideo = 1;
  182. #endif
  183. }
  184. #endif
  185.  
  186. #if    defined(__TURBOC__) && !defined(PLUS)
  187. /* I use my own gets to get around the desqview raw mode bug
  188.    which causes gets not to work right.
  189.    I am doing it only for turbo C right now since its a pain to
  190.    get it right for them all.
  191.    it reads straight from console not via stdin.
  192. */
  193. char *
  194. gets(s)
  195. char *s;
  196. {
  197.     register char *p;
  198.     register int c;
  199.     p = s;
  200.     while ((c = getrch()) != EOF){
  201.         if ( c == '\b' && p > s) {
  202.             p--;
  203.             putch(' ');
  204.             putch('\b');
  205.         }
  206.         else if ( c == '\n' || c == '\r') {
  207.             break;
  208.         } else
  209.             *p++ = c;
  210.     }
  211.     *p = '\0';
  212.     putch('\n');
  213.     return(s);
  214. }
  215. #endif
  216.